package com.ezops.dao;

import java.io.Serializable;

import org.hibernate.Criteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.ezops.dao.generics.dao.hibernate.GenericDAOImpl;
import com.ezops.models.ClientTradeFile;

@Repository
public class ClientTradeDAOImpl extends
		GenericDAOImpl<ClientTradeFile, Serializable> implements ClientTradeDAO {

	@Override
	public int getFailedTradeCount() {
		Criteria criteria = getSession().createCriteria(ClientTradeFile.class);
		criteria.add(Restrictions.eq("status", 2));

		return criteria.list().size();

	}

	@Override
	public int getFailedFileCount() {
		Criteria criteria = getSession().createCriteria(ClientTradeFile.class);
		criteria.add(Restrictions.eq("status", 2));
		criteria.setProjection(Projections.distinct(Projections
				.property("batchId")));
		return criteria.list().size();
	}

	@Override
	public int getClientForBatch(int batchId) {
		Criteria criteria = getSession().createCriteria(ClientTradeFile.class);
		criteria.add(Restrictions.eq("batchId", batchId));
		return ((ClientTradeFile)criteria.list().get(0)).getClientId();
	}

}
